package com.example.run_game;

import java.util.Random;

import com.example.run_game.SubObjective.sotype;

import android.content.Context;
import android.content.res.AssetManager;
import android.location.Location;
import android.util.Log;
import android.widget.Toast;

public class SubObjectiveManager
{
	public SubObjective[] subobjectives;
	private Run rungui;
	AssetManager am;
	SoundManager sounds;
		
	SubObjectiveManager(DbManager db, Checkpoint[] ckps, Player player, Run rungui)
	{
		subobjectives = new SubObjective[5];
		sounds = new SoundManager(rungui.getApplicationContext(),rungui.getApplicationContext().getAssets());
        this.rungui = rungui;
        Random rand = new Random();        
		for(int i=0; i<subobjectives.length; i++)					
			subobjectives[i] = new SubObjective(db, ckps, player, rand.nextInt(6));	
	}	
	
	public String[] getDescriptions()
	{
		String[] descriptions = new String[5];		
		for(int i=0; i<subobjectives.length; i++)		
			descriptions[i] = subobjectives[i].desc;
		return descriptions;
	}
	
	public void testSubObjectives(Player player, Location loc, Location previousLoc, double distance, int time, double speed, int calories)
	{
		String[] tracks = {""};
		for(int i=0; i<subobjectives.length; i++)			
			if(subobjectives[i].isAchieved(loc, previousLoc, distance, time, speed, calories))
			{
				//player.awardXP(subobjectives[i].xpValue);
				Log.d("Score:", "Subojective achieved "  + i + " " + subobjectives[i].desc +"awarding " + subobjectives[i].xpValue + "xp" );
				String toastString = "Objective Achieved: "+ subobjectives[i].desc + ", " + subobjectives[i].xpValue + "xp gained";
				rungui.getrunSesh().getScoreManager().subObjectiveXPBonus(subobjectives[i].xpValue);
				Toast.makeText(rungui.getApplicationContext(), toastString,Toast.LENGTH_SHORT).show();
				rungui.setObjectiveAchieved(i);
				am = rungui.getApplicationContext().getAssets();
				tracks[0] = "ding.mp3";
				sounds.playSound(tracks);
			}			
		
	}
}
